//
//  GetUserInfo.m
//  collection
//
//  Created by zhangjing on 4/19/12.
//  Copyright (c) 2012 Tsinghua University. All rights reserved.
//

#import "GetUserInfo.h"

@implementation GetUserInfo

- (void)initParams {
    
    self.descriptionName = @"user.getbasicinfo";
    
    GetUserInfoRequestData* requestData = [[GetUserInfoRequestData alloc] init];
    self.request = requestData;
    [requestData release];
    
    GetUserInfoResponse* response = [[GetUserInfoResponse alloc] init];
    self.response = response;
    [response release];
}

- (NSString*)buildRequestURL {
    
    GetUserInfoRequestData* requestData = (GetUserInfoRequestData*)self.request;
    
    NSString* requestContent = [NSString stringWithFormat:@"&userId=%lld&qUserId=%lld",
                                requestData.UID,
                                requestData.qUID];
    
    return requestContent;
}

- (void)parseResponse:(NSObject *)data {
    
    GetUserInfoResponse* response = (GetUserInfoResponse*)self.response;
    NSDictionary* dic = (NSDictionary*)data;
    response.user = [self parseOneUser:dic];
}

#pragma mark - [Private methods]

- (UserInfo*)parseOneUser:(NSDictionary*)userData {
    
    UserInfo* newUser = [[UserInfo alloc] init];
    
    NSString* value = nil;
    
    // user ID
    value = [userData objectForKey:@"id"];
    if (value != nil && ![value isEqualToString:@""]) {
        newUser.userID = value.longLongValue;
    }
    
    // nick name
    value = [userData objectForKey:@"nick"];
    if (value != nil && ![value isEqualToString:@""]) {
        newUser.nickname = value;
    }
    
    // avatar
    value = [userData objectForKey:@"avagar"];
    if (value != nil && ![value isEqualToString:@""]) {
        newUser.avatarURL = value;
    }
    
    // signature
    value = [userData objectForKey:@"profile"];
    if (value != nil && ![value isEqualToString:@""]) {
        newUser.signature = value;
    }
    
    // feed num
    value = [userData objectForKey:@"noteNum"];
    if (value != nil && ![value isEqualToString:@""]) {
        newUser.feedNum = value.intValue;
    }
    
    // follower num
    value = [userData objectForKey:@"followerNum"];
    if (value != nil && ![value isEqualToString:@""]) {
        newUser.followerNum = value.longLongValue;
    }
    
    // followee num
    value = [userData objectForKey:@"followeeNum"];
    if (value != nil && ![value isEqualToString:@""]) {
        newUser.followeeNum = value.longLongValue;
    }
    
    // favorite num
    value = [userData objectForKey:@"favorateNum"];
    if (value != nil && ![value isEqualToString:@""]) {
        newUser.favouriteNum = value.intValue;
    }
    
    return newUser;
}

@end
